package com.fc.mall.portal.controller;

import com.fc.mall.base.object.Result;
import com.fc.mall.model.PmsProduct;
import com.fc.mall.portal.domain.ProductQueryParam;
import com.fc.mall.portal.service.ProductService;
import com.fc.mall.portal.vo.PmsProductVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品管理Controller
 * Created by dobuy on 2018/4/26.
 */
@Controller
@Api(tags = "PmsProductController", description = "商品管理")
@RequestMapping("/product")
public class ProductController {
    @Autowired
    private ProductService productService;

    @ApiOperation("根据商品id获取商品信息")
    @RequestMapping(value = "/info/{id}", method = RequestMethod.GET)
    @ResponseBody
    public Object getInfo(@PathVariable Long id) {
        PmsProduct pmsProduct = productService.getInfo(id);
        return Result.success(pmsProduct);
    }

    @ApiOperation("查询商品列表")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public Object getList(ProductQueryParam productQueryParam,
                       @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                       @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        List<PmsProductVO> productList = productService.list(productQueryParam, pageSize, pageNum);
        return Result.success(productList);
    }

}
